<template>
	<up-tabs :list="list1" :current="opt" :scrollable="false" @click="click"></up-tabs>
	<view class="order-box">
		<block v-if="orderList.length>0">
		<block v-for='(item,index) in orderList' :key="index">
		<view class="order-item" @click="orderDetail(item.id)">
			<view class="top">
				<span>订单编号：{{item.tid}}</span>
				<span>待付款</span>
			</view>
			<up-divider></up-divider>
			<!-- 待收货 -->
			<block v-if="item.status == 2">
				<view class="middle" @click.stop="logistics()">
					<view class="middle_left">
						<img class="img" src="@/static/order1.png" alt="" />
					</view>
					<view class="middle_middle">
						<view class="status">已下单</view>
						<view>您的订单由第三方卖家拣货完成，待出库</view>
						<view>2023-09-05  16:52:50</view>
					</view>
					<view class="middle_right">
						<up-icon name="arrow-right" color="#8D8989" size="20"></up-icon>
					</view>
				</view>
			</block>
			<block v-for="(productItem, productIndex) in item.details" :key="productIndex">
				<view class="bottom">
					<img src="" alt="" class="left" />
					<view class="right">
						<view class="name_price">
							<view class="name">
								{{productItem.goods_name}}
							</view>
							<view class="price">
								￥
								<text class="text">{{productItem.total_amount}}</text>
							</view>
						</view>
						<view class="size">
							<text>{{productItem.attr}}</text> <text>x{{productItem.num}}</text>
						</view>
					</view>
				</view>
			</block>
			<view class="btn-box">
				<view class="price">
					实付款￥
					<text class="text">{{item.order_amount}}</text>
				</view>
				<!-- 待付款 -->
				<block v-if="item.status == 1">
					<view class="btn">
						<up-button type="info" customStyle="width: 140rpx;height: 62rpx;margin-top:20rpx" shape="circle" :plain="true" :hairline="true" color="#292A2E" text="去支付"></up-button>
					</view>
				</block>
				<!-- 待收货 -->
				<block v-if="item.status == 2">
					<view class="btn">
						<up-button type="info" customStyle="width: 140rpx;height: 62rpx;margin-top:20rpx;margin-right:10rpx" shape="circle" :plain="true" :hairline="true" color="#908E8E" text="查看物流" @click.stop="logistics(item.id)"></up-button>
						<up-button type="info" customStyle="width: 140rpx;height: 62rpx;margin-top:20rpx" shape="circle" :plain="true" :hairline="true" color="#292A2E" text="去支付"></up-button>
					</view>
				</block>
				<!-- 已完成 -->
				<block v-if="item.status == 3">
					<view class="btn">
						<up-button type="info" customStyle="width: 140rpx;height: 62rpx;margin-top:20rpx;margin-right:10rpx" shape="circle" :plain="true" :hairline="true" color="#292A2E" text="申请售后" @click.stop="apply()"></up-button>
						<up-button type="info" customStyle="width: 140rpx;height: 62rpx;margin-top:20rpx;margin-right:10rpx" shape="circle" :plain="true" :hairline="true" color="#292A2E" text="再来一单" @click.stop="go()"></up-button>
						<up-button type="info" customStyle="width: 140rpx;height: 62rpx;margin-top:20rpx" shape="circle" :plain="true" :hairline="true" color="#908E8E" text="确认收货" @click.stop="sure(item.id)"></up-button>
					</view>
				</block>
				<!-- 已取消 -->
				<block v-if="item.status == 4">
					<view class="btn">
						<up-button type="info" customStyle="width: 140rpx;height: 62rpx;margin-top:20rpx" shape="circle" :plain="true" :hairline="true" color="#292A2E" text="再来一单" @click.stop="go()"></up-button>
					</view>
				</block>
			</view>
		</view>
		</block>
		</block>
		<block v-else>
			<view class="empty-shop-car" >
				<image src="../../static/oder.png" class="empty-shop-car-image" mode=""></image>
				<text style="color: #999999;">抱歉，没有找到订单哦</text>
			</view>
		</block>
		<salepop ref='afterSale'></salepop>
	</view>
</template>

<script>
	import salepop from '@/componets/after-sale-pop/after-sale-pop.vue'
	import {
		http
	} from 'uview-plus'
	export default {
	components: {
			salepop
		},
		data() {
			return {
				list1: [
					{
						name: '待付款'
					},
					{
						name: '待收货'
					},
					{
						name: '已完成'
					},
					{
						name: '已取消'
					}
				],
				index:0,
				opt:0,
				orderList:[]
			}
		},
		onLoad(options){
			this.index = options.index
			this.opt = (options.index - 1)
			this.get_orderList()
		},
		methods:{
			click(e){
				console.log(e)
				this.index = e.index+1
				this.opt = e.index
				this.get_orderList()
			},
			async get_orderList(){
				await http.get('/shop/order',{params:{status:this.index}}).then(res => {
					console.log(res)
					this.orderList = res.items
				});
			},
			//查看物流
			logistics(){
				uni.navigateTo({
					url:'/pages/my_order/logistics?order_id='+e
				})
			},
			//订单详情
			orderDetail(e){
				uni.navigateTo({
					url:'/pages/order/order_detail?order_id='+e
				})
			},
			//再来一单
			go(){
				uni.switchTab({
					url:"/pages/product_List/product_List"
				})
			},
			//确认收货
			async sure(e){
				uni.showModal({
					content:"是否确认收货？",
					success: function(res) {
						if (res.confirm) {
							http.get('/shop/order/receive',{params:{order_id:e}})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			apply() {
				this.$refs.afterSale.setup();
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F9F9F9;
	}
.empty-shop-car {
		width: 750rpx;
		min-height: 680rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

		.empty-shop-car-image {
			width: 460rpx;
			height: 460rpx;
			margin-top: 102rpx;
		}

		text {
			margin-top: 40rpx;
			font-size: 28rpx;
			font-weight: 400;
			color: #fff;
		}

		.empty-shop-car-btn {
			width: 240rpx;
			height: 90rpx;
			background: $main-color;
			border-radius: 200rpx;
			margin-top: 40rpx;
			text-align: center;
			line-height: 90rpx;
			font-size: 32rpx;
			font-weight: 400;
			color: #999999;
		}
	}
	.order-box {
		.order-item {
			width: 718rpx;
			border-radius: 20px;
			margin: 16rpx auto;
			opacity: 1;
			background: #FFFFFF;
			padding: 24rpx 20rpx;
			box-sizing: border-box;

			.top {
				font-size: 26rpx;
				font-weight: normal;
				color: #8D8989;
				@include flex(row);
				justify-content: space-between;
				align-items: center;
			}
			.middle{
				width: 678rpx;
				height: 156rpx;
				border-radius: 10rpx;
				opacity: 1;
				margin: auto;
				margin-bottom: 20rpx;
				background: #F9F9F9;
				padding:20rpx;
				box-sizing: border-box;
				@include flex(row);
				align-items: center;
				justify-content: space-between;
				.middle_left{
					height: 100%;
					.img{
						width: 32.48rpx;
						height: 32rpx;
					}
				}
				.middle_middle{
					height: 100%;
					width: 600rpx;
					margin-left: 14rpx;
					@include flex(column);
					justify-content: space-between;
					font-size: 24rpx;
					color: #8D8989;
					line-height: 37.44rpx;
					.status{
						font-size: 28rpx;
						color: #3D3D3D;
					}
				}
			}
			.bottom {
				@include flex(row);

				.left {
					width: 150rpx;
					height: 150rpx;
				}

				.right {
					flex: 1;
					margin-left: 12rpx;
					font-size: 28rpx;
					font-weight: normal;
					color: #272727;

					.name_price {
						@include flex(row);
						justify-content: space-between;

						.name {
							width: 300rpx;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
						}

						
					}

					.size {
						font-size: 24rpx;
						font-weight: normal;
						color: #737373;
						margin-top: 6rpx;
						display: flex;
						justify-content: space-between
					}
				}

			}
			.btn-box{
				@include flex(column);
				justify-content: flex-end;
				align-items: flex-end;
				.btn{
					@include flex(row)
				}
			}
			.price {
				font-size: 20rpx;
			
				.text {
					font-weight: 500;
					font-size: 28rpx;
				}
			}
		}
	}
</style>